#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e4 + 10;

int n,m,v[N],tim,deg[N],low;
vec G[N];

void solve() {
	n = in,m = in; memset(deg,0,sizeof deg); for(int i = 1;i <= n;i++) { vec tmp; G[i].swap(tmp); }
	for(int i = 1,u,v;i <= m;i++) u = in,v = in,G[u].pb(v),G[v].pb(u),deg[u]++,deg[v]++;
	vec tong[N]; low = n; tim = 0; memset(v,0,sizeof v);
	for(int i = 1;i <= n;i++) tong[deg[i]].pb(i),low = min(low,deg[i]);
	int mx = 0,mxx = 0;
	vec a,b;
	while(low < n) {
		while(tong[low].size() && v[tong[low].back()]) tong[low].pop_back();
		if(!tong[low].size()) { low++; continue; }
		if(low >= mxx) mx = tim,mxx = low;
		int x = tong[low].back(); tong[low].pop_back(); v[x] = ++tim; b.pb(x);
		for(auto y : G[x]) {
			if(v[y]) continue; v[y] = tim;
			for(auto z : G[y])
				--deg[z],tong[deg[z]].pb(z), low = min(low,deg[z]);
		}
	}
	for(int i = 1;i <= n;i++) if(v[i] >= mx) a.pb(i);
	printf("%lu",a.size()); for(auto y : a) printf(" %d",y); puts("");
	printf("%lu",b.size()); for(auto y : b) printf(" %d",y); puts("");
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	for(int T = in;T;T--) solve();
	return 0;
}
